<!--
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 * No deletion without permission, or be held responsible to law.
 * @author LYS
-->
<template>
  <div>
    <BasicTable @register="registerTable">
      <template #tableTitle>
        <Icon :icon="getTitle.icon" class="m-1 pr-1" />
        <span> {{ getTitle.value }} </span>
      </template>
    </BasicTable>
    <InputForm @register="registerDrawer" @success="handleSuccess" />
  </div>
</template>
<script lang="ts">
  export default defineComponent({
    name: 'ViewsBusHtM8ViewConstractList',
  });
</script>
<script lang="ts" setup>
  import { defineComponent } from 'vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { router } from '/@/router';
  import { Icon } from '/@/components/Icon';
  import { BasicTable, BasicColumn, useTable } from '/@/components/Table';
  import { m8ViewConstractDelete, m8ViewHospListUserData } from '/@/api/bus/ht/m8ViewConstract';
  import { useDrawer } from '/@/components/Drawer';
  import { FormProps } from '/@/components/Form';
  import InputForm from './form.vue';

  const { t } = useI18n('bus.zc.m8ViewHosp');
  const { showMessage } = useMessage();
  const getTitle = {
    icon: router.currentRoute.value.meta.icon || 'ant-design:book-outlined',
    value: router.currentRoute.value.meta.title || t('用户注册统计'),
  };

  const searchForm: FormProps = {
    baseColProps: { lg: 6, md: 8 },
    labelWidth: 90,
    schemas: [
      {
        label: t('医疗机构'),
        field: 'name',
        component: 'Input',
      },
      {
        label: t('完善注册'),
        field: 'isReg',
        component: 'Select',
        componentProps: {
          dictType: 'sys_yes_no',
          allowClear: true,
        },
      },
    ],
  };

  const tableColumns: BasicColumn[] = [
    {
      title: t('医疗机构'),
      dataIndex: 'name',
      key: 'a.name',
      sorter: true,
      width: 230,
      align: 'left',
    },
    {
      title: t('用户名称'),
      dataIndex: 'user.userName',
      // key: 'a.name',
      // sorter: true,
      width: 80,
      align: 'left',
    },
    {
      title: t('电话号码'),
      dataIndex: 'user.mobile',
      // key: 'a.name',
      // sorter: true,
      width: 120,
      align: 'left',
    },
    // {
    //   title: t('地址'),
    //   dataIndex: 'addr',
    //   key: 'a.addr',
    //   sorter: true,
    //   width: 180,
    //   align: 'left',
    // },
    // {
    //   title: t('区域'),
    //   dataIndex: 'area',
    //   key: 'a.area',
    //   sorter: true,
    //   width: 80,
    //   align: 'left',
    // },
    // {
    //   title: t('医疗机构性质'),
    //   dataIndex: 'ctype',
    //   key: 'a.ctype',
    //   sorter: true,
    //   width: 130,
    //   align: 'left',
    // },
    // {
    //   title: t('生效日期'),
    //   dataIndex: 'validData',
    //   key: 'a.valid_data',
    //   sorter: true,
    //   width: 120,
    //   align: 'center',
    // },
    // {
    //   title: t('终止日期'),
    //   dataIndex: 'stopData',
    //   key: 'a.stop_data',
    //   sorter: true,
    //   format: 'yyyy-MM-dd',
    //   width: 120,
    //   align: 'center',
    // },
    // {
    //   title: t('将要到期天数'),
    //   dataIndex: 'syDays',
    //   key: 'a.sy_days',
    //   sorter: true,
    //   width: 100,
    //   align: 'center',
    // },
    // {
    //   title: t('合同状态'),
    //   dataIndex: 'htStatus',
    //   key: 'a.ht_status',
    //   sorter: true,
    //   width: 80,
    //   align: 'center',
    //   dictType: 'yf_htzt_status',
    // },
  ];

  // const actionColumn: BasicColumn = {
  //   width: 160,
  //   actions: (record: Recordable) => [
  //     {
  //       icon: 'clarity:note-edit-line',
  //       title: t('编辑医废合同'),
  //       onClick: handleForm.bind(this, { name: record.name }),
  //       auth: 'bus:zc:m8ViewHosp:edit',
  //     },
  //     {
  //       icon: 'ant-design:delete-outlined',
  //       color: 'error',
  //       title: t('删除医废合同'),
  //       popConfirm: {
  //         title: t('是否确认删除医废合同'),
  //         confirm: handleDelete.bind(this, { name: record.name }),
  //       },
  //       auth: 'bus:zc:m8ViewHosp:edit',
  //     },
  //   ],
  // };

  const [registerDrawer, { openDrawer }] = useDrawer();
  const [registerTable, { reload, getForm }] = useTable({
    api: m8ViewHospListUserData,
    beforeFetch: (params) => {
      return params;
    },
    columns: tableColumns,
    formConfig: searchForm,
    showTableSetting: true,
    useSearchForm: true,
    canResize: true,
  });

  function handleForm(record: Recordable) {
    openDrawer(true, record);
  }

  async function handleDelete(record: Recordable) {
    const res = await m8ViewConstractDelete(record);
    showMessage(res.message);
    handleSuccess();
  }

  function handleSuccess() {
    reload();
  }
</script>
